package com.iut.model;

import java.sql.SQLException;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;


public class DatabaseHelper extends OrmLiteSqliteOpenHelper
{
	private static DatabaseHelper instance;

	public DatabaseHelper(Context context, String databaseName,
			CursorFactory factory, int databaseVersion) {
		super(context, databaseName, factory, databaseVersion);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase arg0, ConnectionSource arg1) {
		try { TableUtils.createTable(arg1, Parcelle.class); } catch (SQLException e) { }
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, ConnectionSource arg1, int arg2,
			int arg3) {
		try { TableUtils.dropTable(arg1, Parcelle.class, true); } catch (SQLException e) { }
	}

	public static DatabaseHelper getInstance(Context pContext) 
	{
		if(instance == null)
			instance = new DatabaseHelper(pContext, "PLOTS_DATABASE", null, 1);
		
		return instance;
	}
}
